﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NetROS.Tiers.Entities;

namespace NetRosApp.ZajPart
{
    public partial class KreirajOST : XtraForm
    {
        public KreirajOST()
        {
            InitializeComponent();

        }
        private void textEdit1_Validating(object sender, CancelEventArgs e)
        {
            if (((TextEdit) sender).EditValue == null || ((TextEdit) sender).EditValue.ToString().Length == 0)
            {
                ((TextEdit) sender).ErrorText = "Unesite naziv";
                e.Cancel = true;
            }
        }

        private void sifra_Validating(object sender, CancelEventArgs e)
        {
            if (((TextEdit)sender).EditValue == null || ((TextEdit)sender).EditValue.ToString().Length == 0)
            {
                ((TextEdit)sender).ErrorText = "Unesite sifru";
                e.Cancel = true;
            }
        }
        private void sifra_Validated(object sender, EventArgs e)
        {
            _SifraOST = ((TextEdit)sender).EditValue.ToString();
        }


        private void textEdit1_Validated(object sender, EventArgs e)
        {
            _nazivOST = ((TextEdit) sender).EditValue.ToString();
        }

        public void SetEntitys(TList<OrganizacijaTip> entiteti)
        {
            iOrganizacijaTipBindingSource.DataSource = entiteti;
           
        }

        private void lookUpEdit1_Validated(object sender, EventArgs e)
        {
            _id = Int32.Parse(((LookUpEdit) sender).EditValue.ToString());
        }

        private void lookUpEdit1_Validating(object sender, CancelEventArgs e)
        {
            int tmp;
            if ((((LookUpEdit) sender).EditValue == null) || !int.TryParse(((LookUpEdit) sender).EditValue.ToString(),out tmp))
            {
                ((LookUpEdit) sender).ErrorText = "Izaberite tip";
                e.Cancel = true;
            }
        }

        private String _nazivOST;
        private String _SifraOST;

        public String NazivOst
        {
            get { return _nazivOST; }
            set { _nazivOST = value; }
        }

        public String SifraOst
        {
            get { return _SifraOST; }
            set { _SifraOST = value; }
        }

        private int _id;

        public int IDOstTip
        {
            get { return _id; }
            set { _id = value; }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                DialogResult = DialogResult.OK;
            }
        }
	
	

    }
}